package com.luoxue.execsql.rest.config.application;

import com.luoxue.execsql.rest.bean.datasource.DynamicDataSource;
import com.luoxue.execsql.rest.entity.SysDataSource;
import com.luoxue.execsql.rest.service.impl.DataSourceServiceImpl;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;
import java.util.List;

@Configuration
public class ApplicationRunnerImpl implements ApplicationRunner {

    @Resource
    DataSourceServiceImpl dataSourceService;

    @Resource
    DynamicDataSource dynamicDataSource;

    @Override
    public void run(ApplicationArguments args) {
        List<SysDataSource> sysDataSourceList = dataSourceService.selectByCondition(null);
        dynamicDataSource.updateTargetDataSources(sysDataSourceList);
    }
}
